﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Text.RegularExpressions;

public class DomainLayer : MonoBehaviour {
	public Films films;
	public List<Cinema> cinemas;
	// Use this for initialization
	void Start () {
		films = new Films ();
		cinemas = new List<Cinema> ();
		films.addFilm (1, "X战警：逆转未来", "布莱恩·辛格", "休·杰克曼 迈克尔·法斯宾德", 120, 129, "动作/科幻", "故事的设定发生在当下，变种人族群遭到了前所未有的毁灭性打击，而这一切的根源是“魔形女”瑞文......");
		films.addFilm (2, "澳门风云", "王晶", "周润发/谢霆锋/杜汶泽", 90, 93, "喜剧/动作", "影片讲述的是外号“赢尽天下无敌手”的石一坚和他的朋友家人一起布下并利用局从犯罪集团的手中逃脱的故事");
		films.addFilm (3,"冰雪奇缘" , "" ,"克里斯汀·贝尔/伊迪娜·门泽尔", 100, 102, "", "影片讲述一个严冬咒语令王国被冰天雪地永久覆盖，安娜和山民克里斯托夫以及他的驯鹿搭档组队出发，为寻找姐姐拯救王国展开一段冒险");
		films.addFilm (4, "超凡蜘蛛侠2","", "安德鲁·加菲尔德/艾玛·斯通", 120, 142, "", "影片讲述了彼得·帕克的生活依然很忙，而格温毕业后考虑去牛津大学继续深造。“电光人”出现后，彼得的生活更不得安宁");
		films.addFilm (5, "催眠大师", "","徐峥/莫文蔚", 90, 142, "", "影片讲述了知名心理治疗师徐瑞宁和棘手的女病人任小妍之间发生的故事。");
		films.addFilm (6, "终结者：创世纪", "", "艾米莉亚·克拉克/杰·科特尼", 100, 130, "", "超级电脑“天网”阻止人类抵抗领袖John Connor诞生的行动失败，时隔13年后，在“审判日”到来之前...");
		films.addFilm (7, "人再囧途之泰囧", "", "徐峥/王宝强/黄渤", 100, 105, "", "商业成功人士徐朗用了五年时间发明了一种叫“油霸”的神奇产品','商业成功人士徐朗用了五年时间发明了一种叫“油霸”的神奇产品");
		films.addFilm (8, "夏日大作战", "", "神木隆之介/谷村美月", 120, 114, "", "高中生小矶健二夏日的一天，他应邀来到美丽的学姐——阵内夏希的家乡打工。结果发现......");
		cinemas.Add(new Cinema ("影院A", films));
		cinemas.Add(new Cinema ("影院B", films));
		cinemas.Add(new Cinema ("影院C", films));
	}
	
	// Update is called once per frame
	void Update () {
		
	}
}

public class FilmItem {
    public int number;
	public string name;
	public string director;
	public string actor;
	public int price;
	public int length;
	public string type;
	public string description;
	public FilmItem(int number, string name, string director, string actor, int price, int length, string type, string description) {
		this.number = number;
		this.name = name;
		this.director = director;
		this.actor = actor;
		this.price = price;
		this.length = length;
		this.type = type;
		this.description = description;
	}
};

public class Films {
	List<FilmItem> filmItems;

	public Films() {
		filmItems = new List<FilmItem> ();
	}

	public void addFilm(int number, string name, string director, string actor, int price, int length, string type, string description) {
		filmItems.Add (new FilmItem (number, name, director, actor, price, length, type, description));
	}

	public List<FilmItem> searchFilm(string key) {
		//Debug.Log (key);
		string regular = @".*" + key + @".*";
		//Regex r = new Regex (+key+);
		List<FilmItem> tempList = new List<FilmItem> ();
		//Debug.Log (filmItems);
		foreach (FilmItem x in filmItems) {
			if (Regex.IsMatch (x.name + x.actor + x.description + x.director, regular)) {
				tempList.Add (x);
				//Debug.Log ("success");
			}
		}
		//Debug.Log (tempList);
		return tempList;
	}

	public FilmItem getFilmByNumber(int number) {
		foreach (FilmItem x in filmItems)
			if (x.number == number)
				return x;
		return null;
	}
};

public class Cinema {
	public string name;
	public string introduction;
	public string address;
	public string contactInfo;
	public string notification;
	Films films;
	List<Session> sessions;
	public Cinema(string name, Films films, string intro=null, string add=null, string info=null, string noti=null) {
		this.films = films;
		this.name = name;
		sessions = new List<Session> ();
		sessions.Add (new Session(1));
		sessions.Add (new Session(2));
		sessions.Add (new Session(3));
		sessions.Add (new Session(4));
		sessions.Add (new Session(5));
		sessions.Add (new Session(6));
		sessions.Add (new Session(7));
		sessions.Add (new Session(8));
	}
	public List<Session> getSession(int filmNumber) {
		List<Session> temp = new List<Session> ();
		foreach (Session x in sessions)
			if (x.filmNumber == filmNumber)
				temp.Add (x);
		return temp;
	}
	public Session getSessionById(int id) {
		foreach (Session x in sessions)
			if (x.id == id)
				return x;
		return null;
	}
};

public class Session {
	public int filmNumber;
	public int id;
	static int lastId = 0;
	public string date;
	public string time;
	public string hall;
	int seatX;
	int seatY;
	public bool[,] seats;
	public Session(int filmNumber, string date = "2018/1/1", string time = "12:30", string hall = "4号放映厅", int seatX = 20, int seatY = 20) {
		this.id = filmNumber * 1000 + lastId + 1;
		this.seatX = seatX;
		this.seatY = seatY;
		seats = new bool[seatX, seatY];
		this.filmNumber = filmNumber;
		this.id = id;
		this.date = date;
		this.time = time;
		this.hall = hall;
	}
	public void chooseSeat(int x, int y) {
		seats [x % seatX, y % seatY] = true;
	}
}

public class order {
	Session mySession;
	string Member;
}
